<?php
set_time_limit(0);
include_once (PATH_SQL . 'category_sql.php');
include_once (PATH_MODEL . 'category_model.php');
include_once (PATH_VIEW_ADMIN . 'category_view.php');
$oModelCat = new Model_Category();
$oViewCat = new View_Admin_CategoryManangement($oModelCat);
$oModelCat->setData('page_size',50);
$oModelCat->setData('pagegroup_size',5);
$oModelCat->setData('stylesheet',"paging");

$sAction = $_REQUEST['sAction'];
$oViewCat->displatChooseCategoryIndex($oModelCat);

 switch($sAction)
 {
 	case '':
 	{
 		//$oViewCat->displayFirstListCat($oModelCat);
 		$_SESSION['test_count']=0;
 		break;
 	}
 	case 'list_child_category':
 	{
 		$parent_id=$_REQUEST['parent_id'];
 		$oModelCat->setData('current_level',$_REQUEST['current_level']);
 		$oViewCat->resultXML($oModelCat,'',$oViewCat->ajax_displayListChildCateogry($oModelCat,$parent_id));
 		die();
 		break;
 	}
 	case 'list_parent_category':
 	{
 		$oViewCat->resultXML($oModelCat,'',$oViewCat->ajax_displayListParentCategory($oModelCat));
 		die();
 		break;
 	}
 	case 'do_generate_pro_id':
 	{
 		$cat_id=$_POST['yahoo_id'];
		$today=date('jn');
		$last4=substr($cat_id,-4);
		$num = $oModelCat->getLastestNumberOfProduct();
		$gen_pro_id=$last4.''.$today.''.++$num;
	
		$check=$oModelCat->doInsertGenCategoryId($gen_pro_id,$cat_id);
		if(!$check)
		{
			redir("?sMod=category_index&status=insert_pro_id_fall");
		}
		else
		{
			$row=$oModelCat->getInfoCategoryByYahooID($cat_id);
			echo $row['product_category_name'];
			echo "<script language='javascript'>window.onload=function(){ do_preview('".$gen_pro_id."','".$row['product_category_yahoo_id']."','". $row['product_category_name']  ."','');}</script>";
			//redir("?sMod=category_choose");
		}
 		break;
 	}
 }
 $oViewCat->displayPage($oModelCat);
?>